package com.turing.post.datatranferpmbs.impl;

import java.util.Date;
import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.datatranferpmbs.util.PMBSMchAddTradSummary;
import com.turing.post.datatranferpmbs.util.PMBSMchAddTradSummaryDao;

@Stateless(mappedName = "datatranferpmbs.impl.PMBSMchAddTradSummaryDaoImpl")
@Remote
@Local
public class PMBSMchAddTradSummaryDaoImpl implements PMBSMchAddTradSummaryDao {

	/**
	 * 实体管理器
	 */
	@PersistenceContext
	protected EntityManager _em;

	@SuppressWarnings("unchecked")
	@Override
	public PMBSMchAddTradSummary getMchAddTradSummaryByKey(String merchantNo,
			Date tranDate, String tranSeqNo) {
		String sql = "select * from MchAddTradSummary where merchantNo = ?1 and tranDate = ?2 and tranSeqNo = ?3";
		Query query = _em.createNativeQuery(sql, PMBSMchAddTradSummary.class);
		query.setParameter(1, merchantNo);
		query.setParameter(2, tranDate);
		query.setParameter(3, tranSeqNo);
		List<PMBSMchAddTradSummary> matdlist = query.getResultList();
		if (matdlist.size() > 0) {
			return matdlist.get(0);
		} else {
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PMBSMchAddTradSummary> getMchAddTradSummaryByCond(
			String merchantNo, String tranDate) {
		String sql = "select * from MchAddTradSummary where merchantNo ='"
				+ merchantNo + "' and tranDate = to_date('" + tranDate
				+ "','yyyy-mm-dd') order by merchantNo,tranSeqNo";
		Query query = _em.createNativeQuery(sql, PMBSMchAddTradSummary.class);
		return query.getResultList();
	}
}
